/*
 *说明：访问控制信息表 首页脚本
 *
 *@author liuxun 2012-03-26
*/

var opeForm;
var grid;
var cmdLogGrid;
var sessionLogId;

$(function(){
	opeForm = $('#opeForm');
	
	  $('#tabs').tabs({});// 显示tab标签
	  
	  //toolbars=[{text:'刷新',iconCls:'icon-reload',handler: refreshWin}];
	  
	  var toolbars = [];
	  toolbars=[{text:'刷新会话',iconCls:'icon-reload',handler: refreshSessionList}];

	grid=$('#listTable').datagrid({
		 title: '会话列表',
		 toolbar:toolbars,
		frozenColumns:[[
            //{title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'用户姓名',field:'USR_NAME',align:'center',width:80},
            
            {title:'节点名称',field:'NODE_DECODE',align:'center',width:80},

            {title:'资源名称',field:'RSC_NAME',align:'center',width:80},
            
            {title:'账号',field:'RSC_ACC_ID',align:'center',width:50},

            {title:'协议',field:'PRO_NAME',align:'center',width:40},
            
            //{title:'端口',field:'PORT',align:'center',width:20},
            
            {title:'开始时间',field:'BEGIN_TIME',align:'center',width:80},
            
			{title:'操作',field:'operation',align:'center',width:80,
	        	formatter:function(value,rec){
	        		if(rec.END_TIME == null || rec.END_TIME == ''){
	             		var s = '<a style="cursor:pointer; color:blue" onclick=\'showSupervisory("' + rec.SESSION_LOG_ID + '")\'>监控</a>';
		        	    return s;	        			
	        		}else{
	             		var s = '<a style="cursor:pointer; color:blue" onclick=\'showPlayback("' + rec.SESSION_LOG_ID + '")\'>回放</a>';
		        	    return s;	        			
	        		}
		   		}
		    }            
        ]],
		pagination:false,
		singleSelect: false,
		onClickRow: function(rowIndex, rowData) {
			var selectedSessionLogId = rowData.SESSION_LOG_ID;
			sessionLogId = rowData.SESSION_LOG_ID;
			queryCmdLogOperation(selectedSessionLogId);
	    }
	});
	
	cmdLogGrid=$('#cmdLogTable').datagrid({
		columns:[[

            {title:'开始时间',field:'BEGIN_TIME',align:'center',width:200},

            {title:'命令',field:'CMD',align:'center',width:450}
        ]],
		pagination:true,
		singleSelect: false
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'E_SESSION_LOG!queryMonitorList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//查询命令日志操作
function queryCmdLogOperation(selectedSessionLogId){
	var params = opeForm.serializeObject();
	cmdLogGrid.datagrid("options").pageNumber = 1;
	cmdLogGrid.datagrid({
		url: 'E_CMD_LOG!queryList.do?modelMap.session_log_id=' + selectedSessionLogId
	});
}

//显示回放页面
function showPlayback(key) {
	var url = 'E_SESSION_LOG!showPlayback.do?model.key=' + key;
	openWin(url,'pop','','','','','yes'); 
}

//显示监控页面
function showSupervisory(key){
	var url = 'E_SESSION_LOG!showSupervisory.do?model.key=' + key;
	openWin(url,'pop','','','','','yes'); 
}

function refreshSessionList(){
	queryOperation();
	var selectedSessionLogId = sessionLogId;
	queryCmdLogOperation(selectedSessionLogId);
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}